package zhoufu.sz.sanxiao_check.ui.basic;

import android.databinding.ViewDataBinding;
import android.view.Menu;
import android.view.MenuItem;
import javax.inject.Inject;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.databinding.ActivityBasicMsgItem2Binding;
import zhoufu.sz.sanxiao_check.inject.components.DaggerLoginComponet;
import zhoufu.sz.sanxiao_check.inject.components.LoginComponet;
import zhoufu.sz.sanxiao_check.models.FireDeviceModel;
import zhoufu.sz.sanxiao_check.presents.BasicMsgItem2Presenter;
import zhoufu.sz.sanxiao_check.ui.contract.BasicMsgItem2Contract;
import zhoufu.sz.sanxiao_check.utils.UIUtils;


/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/7/25
 * 消防设施配备情况
 */
public class BasicMsgItem2Activity extends BaseMsgActivity
        implements BasicMsgItem2Contract.View<FireDeviceModel>
{
    ActivityBasicMsgItem2Binding _binding;

    @Inject
    BasicMsgItem2Presenter _presenter;

    @Override protected void initInject()
    {
        setTitle(R.string.title_basic_item8);
        LoginComponet loginComponet = DaggerLoginComponet.builder()
                .activityModule(getActivityModule())
                .appComponent(getAppComponent()).build();
        loginComponet.inject(this);
        _presenter.bidnView(this);
        _presenter.onStart();
    }

    @Override protected int setIndividualId()
    {
        return R.layout.activity_basic_msg_item2;
    }

    @Override protected void initAfterOnCreate(ViewDataBinding binding)
    {
        _binding = (ActivityBasicMsgItem2Binding) binding;
    }

    @Override public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.menu_save, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override public boolean onOptionsItemSelected(MenuItem item)
    {
        if ( item.getItemId() == R.id.menu_save )
        {
            _presenter.update();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override public String SID()
    {
        return mInfoModel.getSID();
    }

    @Override public void setModel(FireDeviceModel model)
    {
        _binding.setModel(model);
    }

    @Override public void updateSuccese()
    {
        UIUtils.showToast(this, "保存成功");
        finish();
    }

    @Override public void showToast(String msg)
    {
        UIUtils.showSnackbar(_binding.getRoot(), msg);
    }

    @Override public void pullFaild()
    {
        UIUtils.showSnackbar(_binding.getRoot(), R.string.toast_network_error);
    }

    @Override public void pullEnd()
    {
        hideProgreesDialog();
    }

    @Override public void pullStart()
    {
        showProgreesDialog();
    }

    @Override protected void onDestroy()
    {
        super.onDestroy();
        _presenter.onDestroy();
    }
}
